#ifndef KEYBIND_H_
#define KEYBIND_H_

#include <gtkmm.h>

#include "conf/collection.h"
#include "conf/attribute.h"
#include "misc.h"

namespace gpyp {

class Application;
struct CommandOpts;

class KeyBind;
typedef boost::shared_ptr<KeyBind> RefKeyBind;

class KeyBindEntry : public conf::Element {
  friend class conf::Collection<KeyBindEntry, KeyBind>;
private:
  RefAttributeAccel     accel_;
  conf::RefAttributeStr command_;

protected:
  virtual void on_load(conf::ConfParser &parser,
                       const char  *element_name,
                       const char **attribute_names,
                       const char **attribute_values);

public:
  inline RefAttributeAccel accel() {
    return accel_;
  }
  inline conf::RefAttributeStr command() {
    return command_;
  }

  KeyBindEntry(const Glib::ustring &name);
};
typedef boost::shared_ptr<KeyBindEntry> RefKeyBindEntry;

class KeyBind : public conf::Collection<KeyBindEntry, KeyBind> {
public:
  typedef sigc::slot<void, CommandOpts &> SlotActivate;

private:
  std::list<RefKeyBind> children_;

protected:
  RefKeyBindEntry on_create_item(const Glib::ustring &name);

public:
  RefKeyBindEntry add_item();
  RefKeyBindEntry add_item(guint key, Gdk::ModifierType mods,
                           const Glib::ustring &command);

  bool run(Application      &app,
           guint             accel_key,
           Gdk::ModifierType accel_mods,
           SlotActivate      slot_activate = SlotActivate());

  inline void append_child(RefKeyBind child) {
    children_.push_back(child);
  }

  KeyBind();
};

}/*gpyp*/

#endif/*KEYBIND_H_*/
